home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / YICN23.ZIP / UNITS / FACTOR.CPP < prev    next >
C/C++ Source or Header  |  1993-02-27  |  4KB  |  123 lines

  1. #include "factor.h"
  2.  
  3.  
  4. directionTable * factor::ficonTable = new directionTable[MAX_ICONS];
  5.  
  6. void factor::spawn(animactor * spawnactor)
  7. {
  8.   animactor::spawn(spawnactor);
  9.   spawnactor->turn(direction);
  10. }
  11.  
  12. void factor::advance(void)
  13. {
  14.   lastMapX = mapX;
  15.   lastMapY = mapY;
  16.   if (spawnedActor != NULL)
  17.   {
  18.     spawnedActor->advance();
  19.     return;
  20.   }
  21.   char newdirection = direction;
  22.   thisFrame = thisFrame->nextFrame;
  23.   if (thisLine == NULL)
  24.     return;
  25.   if (thisLine != NULL)
  26.   {
  27.     switch (thisLine->command)
  28.     {
  29.       case scriptNode::doNothing    : turn(direction); break;//newdirection = center; break;
  30.       case scriptNode::turn        : newdirection = thisLine->mapX; break;
  31.       case scriptNode::fineMoveRel    : fineMoveRel(thisLine->squareX, thisLine->squareY);
  32.               if ((thisLine->squareX < 0) && (thisLine->squareY > 0))
  33.                 newdirection = southwest;
  34.               if ((thisLine->squareX == 0) && (thisLine->squareY > 0))
  35.                 newdirection = south;
  36.               if ((thisLine->squareX > 0) && (thisLine->squareY > 0))
  37.                 newdirection = southeast;
  38.               if ((thisLine->squareX < 0) && (thisLine->squareY == 0))
  39.                 newdirection = west;
  40.               if ((thisLine->squareX == 0) && (thisLine->squareY == 0))
  41.                 newdirection = center;
  42.               if ((thisLine->squareX > 0) && (thisLine->squareY == 0))
  43.                 newdirection = east;
  44.               if ((thisLine->squareX < 0) && (thisLine->squareY < 0))
  45.                 newdirection = northwest;
  46.               if ((thisLine->squareX == 0) && (thisLine->squareY < 0))
  47.                 newdirection = north;
  48.               if ((thisLine->squareX > 0) && (thisLine->squareY < 0))
  49.                 newdirection = northeast;
  50.               break;
  51.     }
  52.     scriptNode * oldLine = thisLine;
  53.     advanceLine();
  54.     if (thisLine == NULL)
  55.       firstLine = NULL;
  56.     delete (oldLine); // free up our script now!
  57.   }
  58.   if (newdirection != direction)
  59.     turn(newdirection);
  60. }
  61.  
  62.  
  63. void factor::turn(byte idirection)
  64. {
  65.   direction = idirection;
  66.   thisFrame = directionIcons[direction];
  67. };
  68.  
  69. void factor::assignIcon(int iconNumber, type mode, char identity)
  70. {
  71.   myIdentity = identity;
  72.   if (myIdentity == 255)
  73.     myIdentity = iconNumber;
  74.   myIconNumber = iconNumber;
  75.   for (int counter = 0; counter < 10; ++counter)
  76.     directionIcons[counter] = ficonTable[iconNumber][counter].firstFrame;
  77.   switch (mode)
  78.   {
  79.     case eightFace:    break;
  80.     case oneFace:    for (counter = 1; counter < 10; ++counter)
  81.               directionIcons[counter] = ficonTable[iconNumber][center].firstFrame;
  82.             break;
  83.     case twoFace:    directionIcons[north] = ficonTable[iconNumber][center].firstFrame;
  84.             directionIcons[south] = ficonTable[iconNumber][center].firstFrame;
  85.     case fourFace:    directionIcons[northwest] = ficonTable[iconNumber][west].firstFrame;
  86.             directionIcons[southwest] = ficonTable[iconNumber][west].firstFrame;
  87.             directionIcons[northeast] = ficonTable[iconNumber][east].firstFrame;
  88.             directionIcons[southeast] = ficonTable[iconNumber][east].firstFrame;
  89.             break;
  90.   }
  91.   for (counter = 0; counter < 10; ++counter)
  92.     if (directionIcons[counter] == NULL)  // if it's not loaded, look @ center
  93.       directionIcons[counter] = ficonTable[iconNumber][center].firstFrame;
  94.   if (direction > 10)
  95.     direction = 5;
  96.   thisFrame = directionIcons[direction];
  97. }
  98.  
  99. void factor::loadFactor(int position, char * special, char * sw, char * s,
  100.             char * se, char * w, char * center, char * e,
  101.             char * nw, char * n, char * ne, yakLib * myYakLib, icon::flagType flags)
  102. {
  103.   ficonTable[position][factor::special].addAll(special, flags, myYakLib);
  104.   ficonTable[position][southwest].addAll(sw, flags, myYakLib);
  105.   ficonTable[position][south].addAll(s, flags, myYakLib);
  106.   ficonTable[position][southeast].addAll(se, flags, myYakLib);
  107.   ficonTable[position][west].addAll(w, flags, myYakLib);
  108.   ficonTable[position][factor::center].addAll(center, flags, myYakLib);
  109.   ficonTable[position][east].addAll(e, flags, myYakLib);
  110.   ficonTable[position][northwest].addAll(nw, flags, myYakLib);
  111.   ficonTable[position][north].addAll(n, flags, myYakLib);
  112.   ficonTable[position][northeast].addAll(ne, flags, myYakLib);
  113. }
  114.  
  115. void factor::clearFactor(int position)
  116. {
  117.   for (int directionCounter = 0; directionCounter < 10; ++directionCounter)
  118.   {
  119.     ficonTable[position][directionCounter].animicon::~animicon();
  120.   }
  121. }
  122.  
  123.